<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="node421.html" />
<link rel="prev" href="network-logging.html" />
<link rel="parent" href="module-logging.html" />
<link rel="next" href="node410.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>14.5.5 Handler Objects</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="14.5.4 sending and receiving"
  href="network-logging.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="14.5 logging  "
  href="module-logging.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="14.5.5.1 StreamHandler"
  href="node410.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="network-logging.html">14.5.4 Sending and receiving</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-logging.html">14.5 logging  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="node410.html">14.5.5.1 StreamHandler</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h2><a name="SECTION0016550000000000000000">
14.5.5 Handler Objects</a>
</h2>

<p>
Handlers have the following attributes and methods. Note that
<tt class="class">Handler</tt> is never instantiated directly; this class acts as a
base for more useful subclasses. However, the <tt class="method">__init__()</tt>
method in subclasses needs to call <tt class="method">Handler.__init__()</tt>.

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2892' xml:id='l2h-2892' class="method">__init__</tt></b>(</nobr></td>
  <td><var>level=<tt class="constant">NOTSET</tt></var>)</td></tr></table></dt>
<dd>
Initializes the <tt class="class">Handler</tt> instance by setting its level, setting
the list of filters to the empty list and creating a lock (using
<tt class="method">createLock()</tt>) for serializing access to an I/O mechanism.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2893' xml:id='l2h-2893' class="method">createLock</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Initializes a thread lock which can be used to serialize access to
underlying I/O functionality which may not be threadsafe.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2894' xml:id='l2h-2894' class="method">acquire</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Acquires the thread lock created with <tt class="method">createLock()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2895' xml:id='l2h-2895' class="method">release</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Releases the thread lock acquired with <tt class="method">acquire()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2896' xml:id='l2h-2896' class="method">setLevel</tt></b>(</nobr></td>
  <td><var>lvl</var>)</td></tr></table></dt>
<dd>
Sets the threshold for this handler to <var>lvl</var>. Logging messages which are
less severe than <var>lvl</var> will be ignored. When a handler is created, the
level is set to <tt class="constant">NOTSET</tt> (which causes all messages to be processed).
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2897' xml:id='l2h-2897' class="method">setFormatter</tt></b>(</nobr></td>
  <td><var>form</var>)</td></tr></table></dt>
<dd>
Sets the <tt class="class">Formatter</tt> for this handler to <var>form</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2898' xml:id='l2h-2898' class="method">addFilter</tt></b>(</nobr></td>
  <td><var>filt</var>)</td></tr></table></dt>
<dd>
Adds the specified filter <var>filt</var> to this handler.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2899' xml:id='l2h-2899' class="method">removeFilter</tt></b>(</nobr></td>
  <td><var>filt</var>)</td></tr></table></dt>
<dd>
Removes the specified filter <var>filt</var> from this handler.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2900' xml:id='l2h-2900' class="method">filter</tt></b>(</nobr></td>
  <td><var>record</var>)</td></tr></table></dt>
<dd>
Applies this handler's filters to the record and returns a true value if
the record is to be processed.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2901' xml:id='l2h-2901' class="method">flush</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Ensure all logging output has been flushed. This version does
nothing and is intended to be implemented by subclasses.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2902' xml:id='l2h-2902' class="method">close</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Tidy up any resources used by the handler. This version does
nothing and is intended to be implemented by subclasses.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2903' xml:id='l2h-2903' class="method">handle</tt></b>(</nobr></td>
  <td><var>record</var>)</td></tr></table></dt>
<dd>
Conditionally emits the specified logging record, depending on
filters which may have been added to the handler. Wraps the actual
emission of the record with acquisition/release of the I/O thread
lock.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2904' xml:id='l2h-2904' class="method">handleError</tt></b>(</nobr></td>
  <td><var>record</var>)</td></tr></table></dt>
<dd>
This method should be called from handlers when an exception is
encountered during an <tt class="method">emit()</tt> call. By default it does nothing,
which means that exceptions get silently ignored. This is what is
mostly wanted for a logging system - most users will not care
about errors in the logging system, they are more interested in
application errors. You could, however, replace this with a custom
handler if you wish. The specified record is the one which was being
processed when the exception occurred.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2905' xml:id='l2h-2905' class="method">format</tt></b>(</nobr></td>
  <td><var>record</var>)</td></tr></table></dt>
<dd>
Do formatting for a record - if a formatter is set, use it.
Otherwise, use the default formatter for the module.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2906' xml:id='l2h-2906' class="method">emit</tt></b>(</nobr></td>
  <td><var>record</var>)</td></tr></table></dt>
<dd>
Do whatever it takes to actually log the specified logging record.
This version is intended to be implemented by subclasses and so
raises a <tt class="exception">NotImplementedError</tt>.
</dl>

<p>

<p><br /></p><hr class='online-navigation' />
<div class='online-navigation'>
<!--Table of Child-Links-->
<a name="CHILD_LINKS"><strong>Subsections</strong></a>

<ul class="ChildLinks">
<li><a href="node410.html">14.5.5.1 StreamHandler</a>
<li><a href="node411.html">14.5.5.2 FileHandler</a>
<li><a href="node412.html">14.5.5.3 RotatingFileHandler</a>
<li><a href="node413.html">14.5.5.4 TimedRotatingFileHandler</a>
<li><a href="node414.html">14.5.5.5 SocketHandler</a>
<li><a href="node415.html">14.5.5.6 DatagramHandler</a>
<li><a href="node416.html">14.5.5.7 SysLogHandler</a>
<li><a href="node417.html">14.5.5.8 NTEventLogHandler</a>
<li><a href="node418.html">14.5.5.9 SMTPHandler</a>
<li><a href="node419.html">14.5.5.10 MemoryHandler</a>
<li><a href="node420.html">14.5.5.11 HTTPHandler</a>
</ul>
<!--End of Table of Child-Links-->
</div>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="14.5.4 sending and receiving"
  href="network-logging.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="14.5 logging  "
  href="module-logging.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="14.5.5.1 StreamHandler"
  href="node410.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="network-logging.html">14.5.4 Sending and receiving</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-logging.html">14.5 logging  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="node410.html">14.5.5.1 StreamHandler</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
